#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

#define N 10

typedef void (*callback)();

void Worker()
{
    int cnt = 10;
    while(cnt--)
    {
        printf("pid: %d, ppid: %d, cnt: %d\n", getpid(), getppid(), cnt);
        sleep(1);
    }
}

void creatSubProcess(int n, callback cb)
{
    for(int i = 0; i < n; i++) 
    {
        sleep(1);
        pid_t id = fork();
        if(id == 0) 
        {
            //child
            printf("creat child process: %d\n", i);
            cb();
            exit(0);
        }
    }

}

int main()
{
    creatSubProcess(N, Worker);
    sleep(20);
    return 0;
}
